package com.demo206_反转链表;



 class ListNode {
    int val;
    ListNode next;
    ListNode() {}
    ListNode(int val) { this.val = val; }
    ListNode(int val, ListNode next) { this.val = val; this.next = next; }
}
public class Solution {
    public ListNode reverseList(ListNode head) {
        ListNode p = head;
        ListNode first = head;
        ListNode newHead = head;
        while (first!=null&&first.next!=null){
            p=first.next;
            first.next=p.next;
            p.next=newHead;
            newHead = p;
        }
        return newHead;
    }
}